static char SccsId[] = "@(#)sptwist.c	1.2   9/21/95";
/*
 *         Copyright (c) KUBOTA Corporation and HUDSON SOFT,
 *                  1994, 1995 All Rights Reserved
 *
 *  This software comprises unpublished confidential information of
 *  KUBOTA Corp. and HUDSON SOFT. It may not be used, copied or made
 *  available to anyone, except in accordance with the license under
 *  which it is furnished.
 */

#define ASL_USE_MACRO

#include <farl.h>
#include <asl.h>

#if !defined( abs )
#define abs(x)        (((x)>=0)?(x):(-(x)))
#endif

#if !defined( cosdi )
#define cosdi(x)        ( (short)FarlGetCos187( (x) % 3600 ) << 1 )
#endif

ASLPt		pt[128][64];

void
main()
{
	int		i, j, cst;
	ASLSct		sct;
	ASLSource	src;

	FX73init();
	FX73_cmap_i5c4();
	FarlInit();
	ASLSetSpriteWindow( 0, 0, 255, 239 );

	sct.head	= ASL_VAL_FNC_TBL | 0;
	sct.cntl	= 0;
	sct.dsp_x_pos	= 96;
	sct.dsp_y_pos	= 96;
	sct.dsp_xy_size = ( ( 64 - 1 ) << ASL_SFT_DSP_X_SIZE )
				| ( ( 64 - 1 ) << ASL_SFT_DSP_Y_SIZE );
	sct.src_xy_pos	= (  0 << ASL_SFT_SRC_X_POS )
				| (  0 << ASL_SFT_SRC_Y_POS );
	sct.src_xy_size	= ( ( 64 - 1 ) << ASL_SFT_SRC_X_SIZE )
				| ( ( 64 - 1 ) << ASL_SFT_SRC_Y_SIZE );
	sct.pt_bank_sel	= 2;
	sct.pt_off_addr	= 0;

	for ( i = 0; i < 128; i++ ) {
		for ( j = 0; j < 64; j++ ) {
			cst = cosdi( ( ( i * 3600 ) - ( i * j * 3600 / 64 ) ) / 128 );
			if ( abs( cst ) == 0 ) {
				pt[i][j].x_off  = 64 - 65 * 64;
				pt[i][j].y_off  = j;
				pt[i][j].x_scan = 65 * 256;
				pt[i][j].y_scan = 0;
			} else {
				pt[i][j].x_off  = 32 - ( 32 * 256 ) / cst;
				pt[i][j].y_off  = j;
				pt[i][j].x_scan = 256 * 256 / cst;
				pt[i][j].y_scan = 0;
			}
		}
	}
	ASLSetParameterTable( 2, 0, 64*128, (ASLPt *)pt );

	for (;;) {
		for ( i =   0; i < 128; i++ ) {
			sct.pt_off_addr = ( i % 128 ) * ( sizeof(ASLPt) * 64 );
			ASLSetSpriteTable( 1, 0, 1, &sct );
			ASLExecuteSprite( 1, 0, 1 );

			/*	Swap buffer.	*/
			ASLSync();
			FarlSwapWindow();
			ASLWaitForSwap();
		}
		for ( i = 127; i >   0; i-- ) {
			sct.pt_off_addr = ( i % 128 ) * ( sizeof(ASLPt) * 64 );
			ASLSetSpriteTable( 1, 0, 1, &sct );
			ASLExecuteSprite( 1, 0, 1 );

			/*	Swap buffer.	*/
			ASLSync();
			FarlSwapWindow();
			ASLWaitForSwap();
		}
	}
}

